﻿
namespace UsingNonMVVMElements.Command
{
    using System;
    using System.Windows.Input;

    internal class GoBackWithWebBrowserDynamicParameterCommand 
        : ICommand
    {
        public bool CanExecute(object parameter)
        {
            bool ret = true;

            if (parameter != null)
            {
                dynamic browser = parameter;
                ret = browser.CanGoBack;
            }

            return ret;
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }


        public void Execute(object parameter)
        {
            if (parameter != null)
            {
                dynamic browser = parameter;
                browser.GoBack();
            }
        }
    }

}
